import Vue from 'vue'
import VueI18n from 'vue-i18n'
//暂时放到public下
import customZhCn from './lang/zh-CN'
import customZhTw from './lang/zh-TW'
import customEnUs from './lang/en-US'

import zhCnLocale from 'view-design/src/locale/lang/zh-CN'
import enUsLocale from 'view-design/src/locale/lang/en-US'
import zhTwLocale from 'view-design/src/locale/lang/zh-TW'

Vue.use(VueI18n)
//从本地缓存取，从浏览器语言取，如果都取不到默认为 英文
let lang = localStorage.getItem('local')
if (!lang){
  const navLang = navigator.language;
  if (!!navLang){
    if (navLang.substring(0,2) === 'en'){
      lang = "en-US";
    }else{
      lang = navLang;
    }
  }else{
    lang = "en-US";
  }
}
//暂时只支持三种
if (!(lang === 'en-US' || lang === 'zh-CN' || lang === 'zh_TW')){
  lang = 'en-US';
}
Vue.config.lang = lang;

/*if (!Vue.config.lang){

}*/


// vue-i18n 6.x+写法
Vue.locale = () => {}
const messages = {
//暂时放到public下
  'zh-CN': Object.assign(zhCnLocale, customZhCn),
  'zh-TW': Object.assign(zhTwLocale, customZhTw),
  'en-US': Object.assign(enUsLocale, customEnUs)
/*  'zh-CN': Object.assign(zhCnLocale, config.zhCn()),
  'zh-TW': Object.assign(zhTwLocale, config.zhTw()),
  'en-US': Object.assign(enUsLocale, config.enUs())*/
}
const i18n = new VueI18n({
  locale: lang,
  silentTranslationWarn: true, //取消打印警告
  messages,

})

export default i18n

// vue-i18n 5.x写法
// Vue.locale('zh-CN', Object.assign(zhCnLocale, customZhCn))
// Vue.locale('en-US', Object.assign(zhTwLocale, customZhTw))
// Vue.locale('zh-TW', Object.assign(enUsLocale, customEnUs))
